home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / ACL / Examples / ACL-World / Sources / Scrolling.cp < prev    next >
Encoding:
Text File  |  1994-10-01  |  3.8 KB  |  175 lines  |  [TEXT/MMCC]

  1.  
  2. /********************************************
  3.  **** ACL-World
  4.  ****
  5.  **** Controls.cp
  6.  ****
  7.  **** Created:      29 August 1994
  8.  **** Modified:     30 August 1994
  9.  **** Version:      0
  10.  **** Compatible:   C++, Mac System 7
  11.  ****
  12.  **** Description:    Scrolling demo.
  13.  ****
  14.  *******************/
  15.  
  16. #include "ACL-World.h"
  17.  
  18. //*************************************
  19.  
  20.  
  21. static const short PICT_BACKGROUND     = 178;
  22. static const short PICT_BACKGROUND2 = 182;
  23.  
  24.  
  25. //*************************************
  26.  
  27. #define    TEXTSTEP1    "\pA background picture may be bigger than the view rectangle. In this case the view rectangle may be scrolled in the background picture. Use the arrows of your keyboard to scroll the view."
  28.  
  29. #define    TEXTSTEP2    "\pACL is able to do circular scrollings. It means that when the visible rectangle scrolls out of the background ACL redisplays the left/top part of the image. Use the arrows of your keyboard to scroll the view."
  30.                          
  31.                     
  32. //*************************************
  33.  
  34. static AnimGfx    *background;
  35. static short    backwidth,backheight;
  36. static Anim        *anims[1];
  37.  
  38.  
  39. //*************************************
  40.  
  41. Boolean ACLWorld::scrolling_advance(void)
  42. {
  43.     short     i;
  44.     Handle     ha;
  45.     Rect    rect;
  46.  
  47.     static short w,h;
  48.  
  49.  
  50.     step++;
  51.     
  52.     GetDItem(dialog,1,&i,&ha,&rect);
  53.     
  54.     switch(step)
  55.     {
  56.         case 1:
  57.         SetIText(ha,TEXTSTEP1);        
  58.         animbase->installbackground(background);
  59.         anims[0] = animbase->createanim(animpers);
  60.         anims[0]->setsequence(2);
  61.         anims[0]->findcursize(&w,&h);
  62.         anims[0]->place(150-(w/2),100-(h/2));
  63.         return FALSE;
  64.  
  65.         case 2:
  66.         SetIText(ha,TEXTSTEP2);    
  67.         background = animbase->newgfx(PICT_BACKGROUND2);
  68.         animbase->installbackground(background);
  69.  
  70.         backwidth = background->getwidth();
  71.         backheight = background->getheight();
  72.         
  73.         ((AnimScrollBase*)animbase)->setscrolloffsetx((backwidth/2) - 150);
  74.         ((AnimScrollBase*)animbase)->setscrolloffsety((backheight/2) - 100);
  75.  
  76.         return FALSE;
  77.     }
  78.     
  79.     
  80.     return TRUE;
  81. }
  82.  
  83.  
  84.  
  85. //*************************************
  86.  
  87. Boolean ACLWorld::do_scrolling(void)
  88. {
  89.     Point p;
  90.     char  key;
  91.     short res;
  92.     Boolean done = FALSE;
  93.     AnimScrollBase *animbase;
  94.  
  95.     pleasewait(TRUE);
  96.  
  97.     ACLWorld::animbase = animbase = new AnimScrollBase();
  98.     
  99.     background = animbase->newgfx(PICT_BACKGROUND);
  100.     animbase->newgfx(PICT_BACKGROUND2);
  101.     animbase->preload_framedef(animpers);
  102.  
  103.     backwidth = background->getwidth();
  104.     backheight = background->getheight();
  105.         
  106.     animbase->buildbuffer(300,200);
  107.     animbase->setbasex(17+80);
  108.     animbase->setbasey(8+7);
  109.  
  110.     animbase->setscrolloffsetx((backwidth/2) - 150);
  111.     animbase->setscrolloffsety((backheight/2) - 100);
  112.  
  113.     pleasewait(FALSE);
  114.  
  115.     step = 0;
  116.     openbasedialog();
  117.     SetWTitle(dialog,"\pScrolling");
  118.     scrolling_advance();
  119.  
  120.     
  121.     for(;;)
  122.     {    
  123.     
  124.         if (step==1)
  125.         {
  126.     
  127.             if (animbase->getscrolloffsetx()+animbase->gethscrollvect()<0 ||
  128.                 (animbase->getscrolloffsetx()+animbase->gethscrollvect()+300>=backwidth)) 
  129.                 animbase->sethscrollvect(0);
  130.  
  131.             if (animbase->getscrolloffsety()+animbase->getvscrollvect()<0 ||
  132.                 (animbase->getscrolloffsety()+animbase->getvscrollvect()+200>=backheight)) 
  133.                 animbase->setvscrollvect(0);
  134.         }
  135.     
  136.         res = processbasedialog(key,p);
  137.         
  138.         if         (res==DO_QUIT) {done=TRUE; break;}
  139.         else if (res==DO_MENU) break;
  140.         else if (res==DO_CONTINUE && scrolling_advance()) break;        
  141.         else if (res==DO_KEY)
  142.         {
  143.             switch(key)
  144.             {
  145.                 case 28: animbase->sethscrollvect(-3); break;
  146.                 case 29: animbase->sethscrollvect(3); break;
  147.                 case 30: animbase->setvscrollvect(-3); break;
  148.                 case 31: animbase->setvscrollvect(3); break;
  149.  
  150.             }
  151.         }
  152.         else if (res==DO_KEYUP)
  153.         {
  154.             switch(key)
  155.             {
  156.                 case 28: animbase->sethscrollvect(0); break;
  157.                 case 29: animbase->sethscrollvect(0); break;
  158.                 case 30: animbase->setvscrollvect(0); break;
  159.                 case 31: animbase->setvscrollvect(0); break;
  160.  
  161.             }
  162.         }    
  163.     }
  164.     
  165.     closebasedialog();
  166.     
  167.     delete animbase;
  168.  
  169.     return done;
  170. }
  171.  
  172. //*************************************
  173.  
  174.  
  175.